/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainPanel.java
 *
 * Created on Oct 27, 2012, 11:16:44 PM
 */
package iapractica.views;

import com.frre.cemami.utils.MathUtils;
import com.frre.cemami.utils.Utils;
import genetics.functions.managers.CruzaManager;
import genetics.functions.managers.MutatorManager;
import genetics.functions.managers.SelectionManager;
import genetics.individuos.Individuo;
import genetics.productos.exceptions.NoMateriaPrimaAddedException;
import iapractica.controllers.MainPanelController;
import iapractica.views.popups.PopUpFactory;
import java.awt.Color;
import java.awt.Component;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 *
 * @author Justo Vargas
 */
public class MainPanelView extends GenericView {

    private HashMap<SelectionManager.Selectors, Integer> selectionCoverageMethods;
    private HashMap<CruzaManager.Cruzators, Integer> cruzaCoverageMethods;
    private HashMap<MutatorManager.Mutators, Integer> mutationsCoverageMethods;
    //the charts
    private JFreeChart jfreeChartScatterPlotProfit;
    private JFreeChart jfreeChartScatterPlotFitness;
    private JFreeChart jfreeChartXYLinePLotProfit;
    private JFreeChart jfreeChartXYLinePLotFitness;
    //the series
    private XYSeriesCollection xySeriesCollectionScatterFitnessPlot;
    private XYSeriesCollection xySeriesCollectionScatterProfitPlot;
    private XYSeriesCollection xySeriesCollectionLineXYProfitPlot;
    private XYSeriesCollection xySeriesCollectionLineXYFitnessPlot;
    //the implementations
    private LinkedList<XYSeries> seriesProfit;
    //the implementations
    private LinkedList<XYSeries> seriesFitness;
    //the panels
    private HashMap<String, ChartPanel> myChartPanelS;
    //the sipinners
    private LinkedList<JSpinner> spinnersCargaDatos = new LinkedList<JSpinner>();
    int iteracionesMaxima;
    double worstAptitudNumber = 0;
    private static final String POPULATION_PROFIT = "Soluciones Por Ganancias";
    private static final String POPULATION_FITNESS = "Soluciones Por Valor de Aptitud";
    private static final String AVERAGE_FITNESS = "Promedio Por Valor de Aptitud";
    private static final String AVERAGE_PROFIT = "Promedio Por Valor de Ganancia";
    private boolean inPauseStatus = false;
    private PopulationView populationView;

    /**
     * Creates new form MainPanel
     */
    public MainPanelView() {
        initComponents();

        this.playBtn.setText("Play");
        init();
        makeJFreChartPanel();

        populationView = new PopulationView();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(iapractica.IAPracticaApp.class).getContext().getResourceMap(MainPanelView.class);
        this.setIconImage(resourceMap.getImageIcon("image.icon").getImage());

        historial.setSelected(true);
        
        iteracionesMax1.setValue(1000);
        indivMax1.setValue(1000);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        mainContainer = new javax.swing.JPanel();
        simlationContainer = new javax.swing.JPanel();
        propertiesManager = new javax.swing.JPanel();
        tabPanel = new javax.swing.JTabbedPane();
        cargaDatos = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jSpinner1 = new javax.swing.JSpinner();
        jSpinner2 = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        jSpinner3 = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        jSpinner4 = new javax.swing.JSpinner();
        jLabel7 = new javax.swing.JLabel();
        jSpinner5 = new javax.swing.JSpinner();
        jLabel8 = new javax.swing.JLabel();
        jSpinner6 = new javax.swing.JSpinner();
        jLabel9 = new javax.swing.JLabel();
        jSpinner7 = new javax.swing.JSpinner();
        jLabel10 = new javax.swing.JLabel();
        jSpinner8 = new javax.swing.JSpinner();
        jLabel11 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        indivMax1 = new javax.swing.JSpinner();
        iteracionesMax1 = new javax.swing.JSpinner();
        jLabel24 = new javax.swing.JLabel();
        historial = new javax.swing.JCheckBox();
        operadoresGeneticos = new javax.swing.JPanel();
        seleccionPanel = new javax.swing.JPanel();
        Metodos = new javax.swing.JPanel();
        elitista = new javax.swing.JCheckBox();
        ranking = new javax.swing.JCheckBox();
        controlCopias = new javax.swing.JCheckBox();
        jLabel12 = new javax.swing.JLabel();
        selectorPercentage = new javax.swing.JSpinner();
        jLabel13 = new javax.swing.JLabel();
        seleccionPanel1 = new javax.swing.JPanel();
        Metodos3 = new javax.swing.JPanel();
        zeroMutation = new javax.swing.JCheckBox();
        random = new javax.swing.JCheckBox();
        adder = new javax.swing.JCheckBox();
        maximizer = new javax.swing.JCheckBox();
        jLabel15 = new javax.swing.JLabel();
        mutatorPercentage = new javax.swing.JSpinner();
        jLabel14 = new javax.swing.JLabel();
        seleccionPanel2 = new javax.swing.JPanel();
        Metodos4 = new javax.swing.JPanel();
        binomial = new javax.swing.JCheckBox();
        multipunto = new javax.swing.JCheckBox();
        jLabel16 = new javax.swing.JLabel();
        cruzaPercentage = new javax.swing.JSpinner();
        jLabel22 = new javax.swing.JLabel();
        simlationProperties = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        velocidad = new javax.swing.JSlider();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        backBtn = new javax.swing.JButton();
        playBtn = new javax.swing.JButton();
        pauseBtn = new javax.swing.JButton();
        nextBnt = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        stadistic = new javax.swing.JPanel();
        statics = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        bestAptitud = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        worstAptitud = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        averageAptitud = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel23 = new javax.swing.JLabel();
        population = new javax.swing.JLabel();
        jPanel8 = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        age = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jProgressBar1 = new javax.swing.JProgressBar();
        selectChartsPanel = new javax.swing.JPanel();
        scatterPlotCombo = new javax.swing.JComboBox();
        useChart = new javax.swing.JCheckBox();
        popuView = new javax.swing.JCheckBox();
        sortData = new javax.swing.JCheckBox();
        linePlotterCombo = new javax.swing.JComboBox();
        ballPanel = new javax.swing.JPanel();
        jLabel26 = new javax.swing.JLabel();
        chartPanel = new javax.swing.JPanel();
        chart1 = new javax.swing.JPanel();
        chart2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(iapractica.IAPracticaApp.class).getContext().getResourceMap(MainPanelView.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        mainContainer.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        mainContainer.setAutoscrolls(true);
        mainContainer.setName("mainContainer"); // NOI18N
        mainContainer.setLayout(new java.awt.GridLayout(1, 0));

        simlationContainer.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("simlationContainer.border.title"), javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP)); // NOI18N
        simlationContainer.setAutoscrolls(true);
        simlationContainer.setName("simlationContainer"); // NOI18N
        simlationContainer.setLayout(new java.awt.GridLayout(2, 0));

        propertiesManager.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("propertiesManager.border.title"))); // NOI18N
        propertiesManager.setName("propertiesManager"); // NOI18N
        propertiesManager.setLayout(new java.awt.GridLayout(1, 0));

        tabPanel.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        tabPanel.setAutoscrolls(true);
        tabPanel.setName("tabPanel"); // NOI18N

        cargaDatos.setName("cargaDatos"); // NOI18N
        cargaDatos.setLayout(new java.awt.GridBagLayout());

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(51, 10, 2, 0);
        cargaDatos.add(jLabel3, gridBagConstraints);

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 20, 0, 0);
        cargaDatos.add(jLabel4, gridBagConstraints);

        jSpinner1.setName("jSpinner1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
        cargaDatos.add(jSpinner1, gridBagConstraints);

        jSpinner2.setName("jSpinner2"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        cargaDatos.add(jSpinner2, gridBagConstraints);

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel5, gridBagConstraints);

        jSpinner3.setName("jSpinner3"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        cargaDatos.add(jSpinner3, gridBagConstraints);

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel6, gridBagConstraints);

        jSpinner4.setName("jSpinner4"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        cargaDatos.add(jSpinner4, gridBagConstraints);

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel7, gridBagConstraints);

        jSpinner5.setName("jSpinner5"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
        cargaDatos.add(jSpinner5, gridBagConstraints);

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel8, gridBagConstraints);

        jSpinner6.setName("jSpinner6"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        cargaDatos.add(jSpinner6, gridBagConstraints);

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 20, 0, 0);
        cargaDatos.add(jLabel9, gridBagConstraints);

        jSpinner7.setName("jSpinner7"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        cargaDatos.add(jSpinner7, gridBagConstraints);

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel10, gridBagConstraints);

        jSpinner8.setName("jSpinner8"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 6;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridheight = 2;
        gridBagConstraints.ipadx = 21;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        cargaDatos.add(jSpinner8, gridBagConstraints);

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.ipadx = 8;
        gridBagConstraints.ipady = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel11, gridBagConstraints);

        jButton1.setIcon(resourceMap.getIcon("jButton1.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 170, 116, 0);
        cargaDatos.add(jButton1, gridBagConstraints);

        jButton2.setIcon(resourceMap.getIcon("jButton2.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 11;
        gridBagConstraints.gridy = 9;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 10;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(12, 23, 116, 26);
        cargaDatos.add(jButton2, gridBagConstraints);

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 20, 0, 0);
        cargaDatos.add(jLabel2, gridBagConstraints);

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 20, 0, 0);
        cargaDatos.add(jLabel1, gridBagConstraints);

        indivMax1.setName("indivMax1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 9;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 61;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 7, 0, 0);
        cargaDatos.add(indivMax1, gridBagConstraints);

        iteracionesMax1.setName("iteracionesMax1"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 9;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.ipadx = 61;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 7, 0, 0);
        cargaDatos.add(iteracionesMax1, gridBagConstraints);

        jLabel24.setIcon(resourceMap.getIcon("jLabel24.icon")); // NOI18N
        jLabel24.setText(resourceMap.getString("jLabel24.text")); // NOI18N
        jLabel24.setName("jLabel24"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 7;
        gridBagConstraints.gridy = 9;
        cargaDatos.add(jLabel24, gridBagConstraints);

        historial.setText(resourceMap.getString("historial.text")); // NOI18N
        historial.setToolTipText(resourceMap.getString("historial.toolTipText")); // NOI18N
        historial.setName("historial"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 9;
        gridBagConstraints.gridy = 7;
        cargaDatos.add(historial, gridBagConstraints);

        tabPanel.addTab("Carga de Datos", cargaDatos);

        operadoresGeneticos.setName("operadoresGeneticos"); // NOI18N
        operadoresGeneticos.setLayout(new java.awt.GridLayout(1, 0));

        seleccionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("seleccionPanel.border.title"))); // NOI18N
        seleccionPanel.setAutoscrolls(true);
        seleccionPanel.setName("seleccionPanel"); // NOI18N
        seleccionPanel.setLayout(new java.awt.GridBagLayout());

        Metodos.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("Metodos.border.title"))); // NOI18N
        Metodos.setName("Metodos"); // NOI18N
        Metodos.setLayout(new java.awt.GridLayout(3, 0));

        elitista.setText(resourceMap.getString("elitista.text")); // NOI18N
        elitista.setName("elitista"); // NOI18N
        Metodos.add(elitista);

        ranking.setText(resourceMap.getString("ranking.text")); // NOI18N
        ranking.setName("ranking"); // NOI18N
        Metodos.add(ranking);

        controlCopias.setText(resourceMap.getString("controlCopias.text")); // NOI18N
        controlCopias.setName("controlCopias"); // NOI18N
        Metodos.add(controlCopias);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 17;
        gridBagConstraints.ipady = -5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 5, 0);
        seleccionPanel.add(Metodos, gridBagConstraints);

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        seleccionPanel.add(jLabel12, gridBagConstraints);

        selectorPercentage.setName("selectorPercentage"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 159;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        seleccionPanel.add(selectorPercentage, gridBagConstraints);

        jLabel13.setIcon(resourceMap.getIcon("jLabel13.icon")); // NOI18N
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N
        seleccionPanel.add(jLabel13, new java.awt.GridBagConstraints());

        operadoresGeneticos.add(seleccionPanel);

        seleccionPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("seleccionPanel1.border.title"))); // NOI18N
        seleccionPanel1.setName("seleccionPanel1"); // NOI18N
        seleccionPanel1.setLayout(new java.awt.GridBagLayout());

        Metodos3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("Metodos3.border.title"))); // NOI18N
        Metodos3.setAutoscrolls(true);
        Metodos3.setName("Metodos3"); // NOI18N
        Metodos3.setLayout(new java.awt.GridLayout(4, 0));

        zeroMutation.setText(resourceMap.getString("zeroMutation.text")); // NOI18N
        zeroMutation.setName("zeroMutation"); // NOI18N
        Metodos3.add(zeroMutation);

        random.setText(resourceMap.getString("random.text")); // NOI18N
        random.setName("random"); // NOI18N
        Metodos3.add(random);

        adder.setText(resourceMap.getString("adder.text")); // NOI18N
        adder.setName("adder"); // NOI18N
        Metodos3.add(adder);

        maximizer.setText(resourceMap.getString("maximizer.text")); // NOI18N
        maximizer.setName("maximizer"); // NOI18N
        Metodos3.add(maximizer);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 23;
        gridBagConstraints.ipady = 8;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(11, 0, 5, 0);
        seleccionPanel1.add(Metodos3, gridBagConstraints);

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        seleccionPanel1.add(jLabel15, gridBagConstraints);

        mutatorPercentage.setName("mutatorPercentage"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 159;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        seleccionPanel1.add(mutatorPercentage, gridBagConstraints);

        jLabel14.setIcon(resourceMap.getIcon("jLabel14.icon")); // NOI18N
        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N
        seleccionPanel1.add(jLabel14, new java.awt.GridBagConstraints());

        operadoresGeneticos.add(seleccionPanel1);

        seleccionPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("seleccionPanel2.border.title"))); // NOI18N
        seleccionPanel2.setName("seleccionPanel2"); // NOI18N
        seleccionPanel2.setLayout(new java.awt.GridBagLayout());

        Metodos4.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("Metodos4.border.title"))); // NOI18N
        Metodos4.setName("Metodos4"); // NOI18N
        Metodos4.setLayout(new java.awt.GridLayout(3, 0));

        binomial.setText(resourceMap.getString("binomial.text")); // NOI18N
        binomial.setName("binomial"); // NOI18N
        Metodos4.add(binomial);

        multipunto.setText(resourceMap.getString("multipunto.text")); // NOI18N
        multipunto.setName("multipunto"); // NOI18N
        Metodos4.add(multipunto);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 17;
        gridBagConstraints.ipady = -5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 5, 0);
        seleccionPanel2.add(Metodos4, gridBagConstraints);

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        seleccionPanel2.add(jLabel16, gridBagConstraints);

        cruzaPercentage.setName("cruzaPercentage"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 159;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(2, 0, 0, 0);
        seleccionPanel2.add(cruzaPercentage, gridBagConstraints);

        jLabel22.setIcon(resourceMap.getIcon("jLabel22.icon")); // NOI18N
        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N
        seleccionPanel2.add(jLabel22, new java.awt.GridBagConstraints());

        operadoresGeneticos.add(seleccionPanel2);

        tabPanel.addTab("Ajuste de Operadores Geneticos", operadoresGeneticos);

        simlationProperties.setName("simlationProperties"); // NOI18N
        simlationProperties.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel9.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel9.setName("jPanel9"); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel5.border.title"))); // NOI18N
        jPanel5.setName("jPanel5"); // NOI18N
        jPanel5.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        velocidad.setPaintLabels(true);
        velocidad.setPaintTicks(true);
        velocidad.setSnapToTicks(true);
        velocidad.setValue(100);
        velocidad.setName("velocidad"); // NOI18N
        velocidad.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                velocidadStateChanged(evt);
            }
        });
        velocidad.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                velocidadPropertyChange(evt);
            }
        });
        jPanel5.add(velocidad, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 558, 30));

        jLabel19.setForeground(resourceMap.getColor("jLabel19.foreground")); // NOI18N
        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N
        jPanel5.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 47, -1, -1));

        jLabel20.setForeground(resourceMap.getColor("jLabel20.foreground")); // NOI18N
        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N
        jPanel5.add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(521, 47, -1, -1));

        jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new java.awt.GridLayout(1, 0));

        backBtn.setIcon(resourceMap.getIcon("backBtn.icon")); // NOI18N
        backBtn.setText(resourceMap.getString("backBtn.text")); // NOI18N
        backBtn.setName("backBtn"); // NOI18N
        backBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                backBtnMouseClicked(evt);
            }
        });
        jPanel4.add(backBtn);

        playBtn.setIcon(resourceMap.getIcon("playBtn.icon")); // NOI18N
        playBtn.setText(resourceMap.getString("playBtn.text")); // NOI18N
        playBtn.setName("playBtn"); // NOI18N
        playBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                playBtnMouseClicked(evt);
            }
        });
        playBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playBtnActionPerformed(evt);
            }
        });
        jPanel4.add(playBtn);

        pauseBtn.setIcon(resourceMap.getIcon("pauseBtn.icon")); // NOI18N
        pauseBtn.setText(resourceMap.getString("pauseBtn.text")); // NOI18N
        pauseBtn.setName("pauseBtn"); // NOI18N
        pauseBtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                pauseBtnMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pauseBtnMouseClicked(evt);
            }
        });
        jPanel4.add(pauseBtn);

        nextBnt.setIcon(resourceMap.getIcon("nextBnt.icon")); // NOI18N
        nextBnt.setText(resourceMap.getString("nextBnt.text")); // NOI18N
        nextBnt.setName("nextBnt"); // NOI18N
        nextBnt.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nextBntMouseClicked(evt);
            }
        });
        jPanel4.add(nextBnt);

        jButton3.setIcon(resourceMap.getIcon("jButton3.icon")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel4.add(jButton3);

        stadistic.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("stadistic.border.title"))); // NOI18N
        stadistic.setName("stadistic"); // NOI18N
        stadistic.setLayout(new java.awt.GridLayout(6, 0));

        statics.setText(resourceMap.getString("statics.text")); // NOI18N
        statics.setName("statics"); // NOI18N
        statics.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                staticsItemStateChanged(evt);
            }
        });
        statics.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                staticsActionPerformed(evt);
            }
        });
        stadistic.add(statics);

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N
        jPanel1.add(jLabel17);

        bestAptitud.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        bestAptitud.setText(resourceMap.getString("bestAptitud.text")); // NOI18N
        bestAptitud.setName("bestAptitud"); // NOI18N
        jPanel1.add(bestAptitud);

        stadistic.add(jPanel1);

        jPanel2.setName("jPanel2"); // NOI18N
        jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N
        jPanel2.add(jLabel18);

        worstAptitud.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        worstAptitud.setText(resourceMap.getString("worstAptitud.text")); // NOI18N
        worstAptitud.setName("worstAptitud"); // NOI18N
        jPanel2.add(worstAptitud);

        stadistic.add(jPanel2);

        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS));

        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N
        jPanel3.add(jLabel21);

        averageAptitud.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        averageAptitud.setText(resourceMap.getString("averageAptitud.text")); // NOI18N
        averageAptitud.setName("averageAptitud"); // NOI18N
        jPanel3.add(averageAptitud);

        stadistic.add(jPanel3);

        jPanel6.setName("jPanel6"); // NOI18N
        jPanel6.setLayout(new javax.swing.BoxLayout(jPanel6, javax.swing.BoxLayout.LINE_AXIS));

        jLabel23.setText(resourceMap.getString("jLabel23.text")); // NOI18N
        jLabel23.setName("jLabel23"); // NOI18N
        jPanel6.add(jLabel23);

        population.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        population.setText(resourceMap.getString("population.text")); // NOI18N
        population.setName("population"); // NOI18N
        jPanel6.add(population);

        stadistic.add(jPanel6);

        jPanel8.setName("jPanel8"); // NOI18N
        jPanel8.setLayout(new javax.swing.BoxLayout(jPanel8, javax.swing.BoxLayout.LINE_AXIS));

        jLabel25.setText(resourceMap.getString("jLabel25.text")); // NOI18N
        jLabel25.setName("jLabel25"); // NOI18N
        jPanel8.add(jLabel25);

        age.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        age.setText(resourceMap.getString("age.text")); // NOI18N
        age.setName("age"); // NOI18N
        jPanel8.add(age);

        stadistic.add(jPanel8);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel7.border.title"))); // NOI18N
        jPanel7.setName("jPanel7"); // NOI18N
        jPanel7.setLayout(new java.awt.GridLayout(1, 0));

        jProgressBar1.setName("jProgressBar1"); // NOI18N
        jPanel7.add(jProgressBar1);

        selectChartsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("selectChartsPanel.border.title"))); // NOI18N
        selectChartsPanel.setName("selectChartsPanel"); // NOI18N
        selectChartsPanel.setLayout(new java.awt.GridLayout(1, 0));

        scatterPlotCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        scatterPlotCombo.setName("scatterPlotCombo"); // NOI18N
        scatterPlotCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                scatterPlotComboItemStateChanged(evt);
            }
        });
        scatterPlotCombo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                scatterPlotComboPropertyChange(evt);
            }
        });
        selectChartsPanel.add(scatterPlotCombo);

        useChart.setText(resourceMap.getString("useChart.text")); // NOI18N
        useChart.setName("useChart"); // NOI18N
        useChart.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                useChartItemStateChanged(evt);
            }
        });
        useChart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useChartActionPerformed(evt);
            }
        });
        selectChartsPanel.add(useChart);

        popuView.setText(resourceMap.getString("popuView.text")); // NOI18N
        popuView.setName("popuView"); // NOI18N
        popuView.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                popuViewItemStateChanged(evt);
            }
        });
        selectChartsPanel.add(popuView);

        sortData.setText(resourceMap.getString("sortData.text")); // NOI18N
        sortData.setName("sortData"); // NOI18N
        sortData.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                sortDataItemStateChanged(evt);
            }
        });
        selectChartsPanel.add(sortData);

        linePlotterCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        linePlotterCombo.setName("linePlotterCombo"); // NOI18N
        linePlotterCombo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                linePlotterComboItemStateChanged(evt);
            }
        });
        linePlotterCombo.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                linePlotterComboPropertyChange(evt);
            }
        });
        selectChartsPanel.add(linePlotterCombo);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 593, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 599, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(selectChartsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(2, 2, 2)
                .addComponent(stadistic, javax.swing.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(selectChartsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(stadistic, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(0, 6, Short.MAX_VALUE))
        );

        simlationProperties.add(jPanel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 800, 220));

        ballPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        ballPanel.setName("ballPanel"); // NOI18N

        jLabel26.setFont(resourceMap.getFont("jLabel26.font")); // NOI18N
        jLabel26.setText(resourceMap.getString("jLabel26.text")); // NOI18N
        jLabel26.setName("jLabel26"); // NOI18N
        ballPanel.add(jLabel26);

        simlationProperties.add(ballPanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 230, 800, 60));

        tabPanel.addTab("Propiedades Simulacion", simlationProperties);

        propertiesManager.add(tabPanel);

        simlationContainer.add(propertiesManager);

        chartPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("chartPanel.border.title"))); // NOI18N
        chartPanel.setAutoscrolls(true);
        chartPanel.setName("chartPanel"); // NOI18N
        chartPanel.setLayout(new java.awt.GridLayout(1, 0));

        chart1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        chart1.setName("chart1"); // NOI18N
        chart1.setLayout(new java.awt.GridLayout(1, 0));
        chartPanel.add(chart1);

        chart2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        chart2.setName("chart2"); // NOI18N
        chart2.setLayout(new java.awt.GridLayout(1, 0));
        chartPanel.add(chart2);

        simlationContainer.add(chartPanel);

        mainContainer.add(simlationContainer);

        getContentPane().add(mainContainer);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        for (JSpinner jSpinner : spinnersCargaDatos) {
            Integer number = (int) MathUtils.getRandomNumber(0, 1000);
            jSpinner.setValue(number);
        }
        
         iteracionesMax1.setValue(1000);
        indivMax1.setValue(1000);
        
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        int[] valores = new int[8];
        int sumatoriaMatPrima = 0;
        for (JSpinner jSpinner : spinnersCargaDatos) {
            try {
                if (jSpinner.getName().startsWith("j")) {
                    int value = Integer.parseInt(jSpinner.getValue().toString());
                    String name = jSpinner.getName().substring(jSpinner.getName().length() - 1);
                    int pos = Integer.parseInt(name);
                    valores[pos - 1] = value;
                    sumatoriaMatPrima += value;
                }
            }
            catch (NumberFormatException e) {
                PopUpFactory.showErrorPopUP(this, "Los Campos deben ser solamente numeros");
                return;
            }
        }

        if (sumatoriaMatPrima == 0) {
            PopUpFactory.showErrorPopUP(this, "No podes comenzar una simulacion con 0 de materia prima en todos lados");
            return;
        }

        int individuosMaximos = Integer.parseInt(indivMax1.getValue().toString());
        if (individuosMaximos == 0) {
            PopUpFactory.showErrorPopUP(this, "No podes comenzar una simulacion con 0 individuos");
            return;
        } else if (individuosMaximos <= 99) {
            PopUpFactory.showErrorPopUP(this, "No podes comenzar una simulacion con menos de 100 individuos");
            return;
        }
        
        // comienzan las combinaciones de casos erroneos
        int matPrima = Integer.parseInt(jSpinner6.getValue().toString());
        if (matPrima == 0){
            PopUpFactory.showErrorPopUP(this, "Esta materia prima no puede ser cero debido a que todos los productos la usan");
            return;
        }

        int matPrima1 = Integer.parseInt(jSpinner1.getValue().toString());
        int matPrima2 = Integer.parseInt(jSpinner2.getValue().toString());
        if (matPrima1 == 0 && matPrima2 == 0){
            PopUpFactory.showErrorPopUP(this, "Esta materias prima no puede ser cero debido a que todos los productos la usan");
            return;
        }
        
        //finalizan las combinaciones de casos erroneos
        
         iteracionesMaxima = Integer.parseInt(iteracionesMax1.getValue().toString());
        if (iteracionesMaxima == 0) {
            PopUpFactory.showErrorPopUP(this, "No podes comenzar una simulacion con 0 iteraciones");
            return;
        }
        
        MainPanelController main = (MainPanelController) this.getController();
        main.addMateriaPrima(valores);
        main.setMaximumPopulation(individuosMaximos);
        main.setMaximumAge(iteracionesMaxima);
        main.setHistorialActive(historial.isSelected());

        PopUpFactory.showConfirmPopUP(this, "Valores Agregados con exito");
    }//GEN-LAST:event_jButton2ActionPerformed

    private void playBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playBtnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_playBtnActionPerformed

    private void useChartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useChartActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_useChartActionPerformed

    private void staticsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_staticsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_staticsActionPerformed

    private void staticsItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_staticsItemStateChanged
        // TODO add your handling code here:
        enableStadistics();
    }//GEN-LAST:event_staticsItemStateChanged

    private void useChartItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useChartItemStateChanged
        // TODO add your handling code here:
        boolean value = useChart.isSelected();
        chartPanel.setEnabled(value);
        // jfreeChartScatterPlot.setNotify(value);
        this.chartPanel.setEnabled(value);
    }//GEN-LAST:event_useChartItemStateChanged

    private void velocidadPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_velocidadPropertyChange
        // TODO add your handling code here:
    }//GEN-LAST:event_velocidadPropertyChange

    private void velocidadStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_velocidadStateChanged
        // TODO add your handling code here:
        MainPanelController main = (MainPanelController) this.getController();
        if (main != null) {
            main.setSimulationVelocity(this.velocidad.getValue());
        }
    }//GEN-LAST:event_velocidadStateChanged

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        MainPanelController main = (MainPanelController) this.getController();
        main.destroyCurrentSimulation();
        this.enablePlayButton(true);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void playBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playBtnMouseClicked
        // TODO add your handling code here:
        if (validateSubmit()) {
            MainPanelController main = (MainPanelController) this.getController();
            if (!main.threadIsRunning()) {
                try {
                    resetCharts();
                    main.startSimulation();
                    this.enablePlayButton(false);
                }
                catch (NoMateriaPrimaAddedException ex) {
                    PopUpFactory.showErrorPopUP(this, "No agresgaste materia prima para comenzar con la simulacion");
                }
            }
        } else {
            this.tabPanel.setSelectedIndex(1);
        }

    }//GEN-LAST:event_playBtnMouseClicked

    private boolean validateSubmit() {
        int percentage = 0;
        try {
            percentage += Integer.parseInt(selectorPercentage.getValue().toString());
            percentage += Integer.parseInt(cruzaPercentage.getValue().toString());
            percentage += Integer.parseInt(mutatorPercentage.getValue().toString());
        }
        catch (NumberFormatException e) {
            PopUpFactory.showErrorPopUP(this, "Los Campos En la seleccion de valores para operadores \n deben ser solamente numeros");
            return false;
        }

        if (percentage > 100) {
            PopUpFactory.showErrorPopUP(this, "La sumatoria de los Campos en la seleccion de valores para operadores \n no debe de superar 100");
            return false;
        } else if (percentage == 0) {
            PopUpFactory.showErrorPopUP(this, "La sumatoria de los Campos en la seleccion de valores para operadores \n debe de ser igual 100");
            return false;
        }
        
        boolean rankin = ranking.isSelected();
        boolean copias = controlCopias.isSelected();
        boolean elitista2 = elitista.isSelected();

        if (!rankin && !copias && !elitista2 && Integer.parseInt(selectorPercentage.getValue().toString()) > 0) {
            PopUpFactory.showErrorPopUP(this, "Debes elejir al menos un metodo de seleccion");
            return false;
        } else if (!rankin && !copias && elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 100);
        } else if (!rankin && copias && !elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 100);
        } else if (!rankin && copias && elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 50);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 50);
        } else if (rankin && !copias && !elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 100);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 0);
        } else if (rankin && !copias && elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 50);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 0);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 50);
        } else if (rankin && copias && !elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 50);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 50);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 0);
        } else if (rankin && copias && elitista2) {
            //set initial values
            selectionCoverageMethods.put(SelectionManager.Selectors.RANKING_SELECTOR, 40);
            selectionCoverageMethods.put(SelectionManager.Selectors.COPY_CONTROL_SELECTOR, 40);
            selectionCoverageMethods.put(SelectionManager.Selectors.BEST_SELECTOR, 20);
        } else {
            logguer.logError("La cague en seleccion");
        }

        boolean bino = binomial.isSelected();
        boolean multi = multipunto.isSelected();

        if (!multi && !bino && Integer.parseInt(cruzaPercentage.getValue().toString()) > 0) {
            PopUpFactory.showErrorPopUP(this, "Debes elejir al menos un metodo de Cruza");
            return false;
        } else if (!multi && bino) {
            cruzaCoverageMethods.put(CruzaManager.Cruzators.BINOMIAL, 100);
            cruzaCoverageMethods.put(CruzaManager.Cruzators.MULTIPUNTO, 0);
        } else if (multi && !bino) {
            cruzaCoverageMethods.put(CruzaManager.Cruzators.BINOMIAL, 0);
            cruzaCoverageMethods.put(CruzaManager.Cruzators.MULTIPUNTO, 100);
        } else if (multi && bino) {
            cruzaCoverageMethods.put(CruzaManager.Cruzators.BINOMIAL, 50);
            cruzaCoverageMethods.put(CruzaManager.Cruzators.MULTIPUNTO, 50);
        } else {
            logguer.logError("La cague en cruza");
        }


        boolean r = random.isSelected();
        boolean z = zeroMutation.isSelected();
        boolean a = adder.isSelected();
        boolean m = maximizer.isSelected();

        if (!r && !z && !a && !m && Integer.parseInt(mutatorPercentage.getValue().toString()) > 0) {
            PopUpFactory.showErrorPopUP(this, "Debes elejir al menos un metodo de Mutacion");
            return false;
        } else if (!r && !z && !a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 100);
        } else if (!r && !z && a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 100);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (!r && !z && a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 50);
        } else if (!r && z && !a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 100);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (!r && z && !a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 50);
        } else if (!r && z && a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (!r && z && a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 20);
        } else if (r && !z && !a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 100);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (r && !z && !a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 50);
        } else if (r && !z && a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (r && !z && a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 20);
        } else if (r && z && !a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 50);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (r && z && !a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 20);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 0);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 40);
        } else if (r && z && a && !m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 20);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 40);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 0);
        } else if (r && z && a && m) {
            mutationsCoverageMethods.put(MutatorManager.Mutators.RANDOM, 25);
            mutationsCoverageMethods.put(MutatorManager.Mutators.ZERO, 25);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MINIMUM, 25);
            mutationsCoverageMethods.put(MutatorManager.Mutators.MAXIMIZER, 25);
        } else {
            logguer.logError("La cague en mutacion");
        }

        MainPanelController main = (MainPanelController) this.getController();
        main.setGAOperators(Integer.parseInt(selectorPercentage.getValue().toString()), Integer.parseInt(mutatorPercentage.getValue().toString()), Integer.parseInt(cruzaPercentage.getValue().toString()), mutationsCoverageMethods, selectionCoverageMethods, cruzaCoverageMethods);

        return true;
    }

    private void scatterPlotComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_scatterPlotComboItemStateChanged
        // TODO add your handling code here:
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                chart1.removeAll();
                String key = scatterPlotCombo.getSelectedItem().toString();
                chart1.add(myChartPanelS.get(key));
            }
        });
    }//GEN-LAST:event_scatterPlotComboItemStateChanged

    private void linePlotterComboItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_linePlotterComboItemStateChanged
        // TODO add your handling code here:
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                chart2.removeAll();
                String key = linePlotterCombo.getSelectedItem().toString();
                chart2.add(myChartPanelS.get(key));
            }
        });
    }//GEN-LAST:event_linePlotterComboItemStateChanged

    private void scatterPlotComboPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_scatterPlotComboPropertyChange
        // TODO add your handling code here:
        // System.out.println(this.scatterPlotCombo.getSelectedItem());
    }//GEN-LAST:event_scatterPlotComboPropertyChange

    private void linePlotterComboPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_linePlotterComboPropertyChange
        // TODO add your handling code here:
        //  System.out.println(this.linePlotterCombo.getSelectedItem());
    }//GEN-LAST:event_linePlotterComboPropertyChange

    private void sortDataItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_sortDataItemStateChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_sortDataItemStateChanged

    private void pauseBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseBtnMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_pauseBtnMouseClicked

    private void pauseBtnMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseBtnMouseReleased
        // TODO add your handling code here:
        if (historial.isSelected()) {
            inPauseStatus = !inPauseStatus;
            this.nextBnt.setEnabled(inPauseStatus);
            this.backBtn.setEnabled(inPauseStatus);
            MainPanelController main = (MainPanelController) this.getController();
            main.pauseSimulation(inPauseStatus);
        }
    }//GEN-LAST:event_pauseBtnMouseReleased

    private void nextBntMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextBntMouseClicked
        // TODO add your handling code here:
        if (inPauseStatus) {
            MainPanelController main = (MainPanelController) this.getController();
            main.forwardOneAge();
        }
    }//GEN-LAST:event_nextBntMouseClicked

    private void backBtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_backBtnMouseClicked
        // TODO add your handling code here:
        if (inPauseStatus) {
            backBtn.setEnabled(false);
            MainPanelController main = (MainPanelController) this.getController();

            for (XYSeries series : seriesProfit) {
                if (series.getItemCount() > 0) {
                    series.remove(series.getItemCount() - 1);
                }
            }

            for (XYSeries series : seriesFitness) {
                if (series.getItemCount() > 0) {
                    series.remove(series.getItemCount() - 1);
                }
            }

            main.getBackOneAge();
        }

    }//GEN-LAST:event_backBtnMouseClicked

    private void popuViewItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_popuViewItemStateChanged
        // TODO add your handling code here:
        this.populationView.setVisible(popuView.isSelected());
    }//GEN-LAST:event_popuViewItemStateChanged
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Metodos;
    private javax.swing.JPanel Metodos3;
    private javax.swing.JPanel Metodos4;
    private javax.swing.JCheckBox adder;
    private javax.swing.JLabel age;
    private javax.swing.JLabel averageAptitud;
    private javax.swing.JButton backBtn;
    private javax.swing.JPanel ballPanel;
    private javax.swing.JLabel bestAptitud;
    private javax.swing.JCheckBox binomial;
    private javax.swing.JPanel cargaDatos;
    private javax.swing.JPanel chart1;
    private javax.swing.JPanel chart2;
    private javax.swing.JPanel chartPanel;
    private javax.swing.JCheckBox controlCopias;
    private javax.swing.JSpinner cruzaPercentage;
    private javax.swing.JCheckBox elitista;
    private javax.swing.JCheckBox historial;
    private javax.swing.JSpinner indivMax1;
    private javax.swing.JSpinner iteracionesMax1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JSpinner jSpinner2;
    private javax.swing.JSpinner jSpinner3;
    private javax.swing.JSpinner jSpinner4;
    private javax.swing.JSpinner jSpinner5;
    private javax.swing.JSpinner jSpinner6;
    private javax.swing.JSpinner jSpinner7;
    private javax.swing.JSpinner jSpinner8;
    private javax.swing.JComboBox linePlotterCombo;
    private javax.swing.JPanel mainContainer;
    private javax.swing.JCheckBox maximizer;
    private javax.swing.JCheckBox multipunto;
    private javax.swing.JSpinner mutatorPercentage;
    private javax.swing.JButton nextBnt;
    private javax.swing.JPanel operadoresGeneticos;
    private javax.swing.JButton pauseBtn;
    private javax.swing.JButton playBtn;
    private javax.swing.JCheckBox popuView;
    private javax.swing.JLabel population;
    private javax.swing.JPanel propertiesManager;
    private javax.swing.JCheckBox random;
    private javax.swing.JCheckBox ranking;
    private javax.swing.JComboBox scatterPlotCombo;
    private javax.swing.JPanel seleccionPanel;
    private javax.swing.JPanel seleccionPanel1;
    private javax.swing.JPanel seleccionPanel2;
    private javax.swing.JPanel selectChartsPanel;
    private javax.swing.JSpinner selectorPercentage;
    private javax.swing.JPanel simlationContainer;
    private javax.swing.JPanel simlationProperties;
    private javax.swing.JCheckBox sortData;
    private javax.swing.JPanel stadistic;
    private javax.swing.JCheckBox statics;
    private javax.swing.JTabbedPane tabPanel;
    private javax.swing.JCheckBox useChart;
    private javax.swing.JSlider velocidad;
    private javax.swing.JLabel worstAptitud;
    private javax.swing.JCheckBox zeroMutation;
    // End of variables declaration//GEN-END:variables

    public JPanel getChartPanel() {
        return chartPanel;
    }

    public void permitGoBack(boolean value) {
        this.backBtn.setEnabled(value);
    }

    @Override
    public void reset() {
    }

    private void makeJFreChartPanel() {
        //create the plots
        xySeriesCollectionScatterProfitPlot = new XYSeriesCollection();
        xySeriesCollectionScatterFitnessPlot = new XYSeriesCollection();

        xySeriesCollectionLineXYFitnessPlot = createLineXYSampleData(seriesFitness, "Fitness");
        xySeriesCollectionLineXYProfitPlot = createLineXYSampleData(seriesProfit, "Profit");

        //create 
        myChartPanelS.put(POPULATION_PROFIT, createChartPanel(POPULATION_PROFIT, "Individuos", "Ganancias", jfreeChartScatterPlotProfit, xySeriesCollectionScatterProfitPlot));
        myChartPanelS.put(POPULATION_FITNESS, createChartPanel(POPULATION_FITNESS, "Individuos", "Fitness", jfreeChartScatterPlotFitness, xySeriesCollectionScatterFitnessPlot));

        myChartPanelS.put(AVERAGE_PROFIT, createLineChartPanel(AVERAGE_PROFIT, "Individuos", "Ganancias", jfreeChartXYLinePLotProfit, xySeriesCollectionLineXYProfitPlot));
        myChartPanelS.put(AVERAGE_FITNESS, createLineChartPanel(AVERAGE_FITNESS, "Individuos", "Fitness", jfreeChartXYLinePLotFitness, xySeriesCollectionLineXYFitnessPlot));


        //this.chart1.add(myChartPanelS.get(POPULATION_FITNESS));
        this.chart1.add(myChartPanelS.get(POPULATION_PROFIT));
        this.chart2.add(myChartPanelS.get(AVERAGE_PROFIT));
        //this.chart2.add(myChartPanelS.get(AVERAGE_FITNESS));

        this.scatterPlotCombo.setSelectedItem(POPULATION_PROFIT);
        this.linePlotterCombo.setSelectedItem(AVERAGE_PROFIT);
    }

    private ChartPanel createChartPanel(String title, String x, String y, JFreeChart thePlot, XYSeriesCollection myPlot) {
        thePlot = ChartFactory.createScatterPlot(
                title, x, y, myPlot,
                PlotOrientation.VERTICAL, true, true, false);
        XYPlot xyScatterPlot = (XYPlot) thePlot.getPlot();
        xyScatterPlot.setDomainCrosshairVisible(true);
        xyScatterPlot.setRangeCrosshairVisible(true);
        NumberAxis domain = (NumberAxis) xyScatterPlot.getDomainAxis();
        domain.setVerticalTickLabels(true);
        return new ChartPanel(thePlot);
    }

    private ChartPanel createLineChartPanel(String title, String x, String y, JFreeChart thePlot, XYSeriesCollection seriesContainer) {
        /// create the chart...



        thePlot = ChartFactory.createXYLineChart(
                title, // chart title
                x, // x axis label
                y, // y axis label
                seriesContainer, // data
                PlotOrientation.VERTICAL,
                true, // include legend
                true, // tooltips
                false // urls
                );

        XYPlot xyScatterPlot = (XYPlot) thePlot.getPlot();
        xyScatterPlot.setDomainCrosshairVisible(true);
        xyScatterPlot.setRangeCrosshairVisible(true);
        NumberAxis domain = (NumberAxis) xyScatterPlot.getDomainAxis();
        domain.setVerticalTickLabels(true);
        xyScatterPlot.getRenderer().setSeriesPaint(0, Color.RED);
        xyScatterPlot.getRenderer().setSeriesPaint(1, Color.BLACK);
        xyScatterPlot.getRenderer().setSeriesPaint(2, Color.BLUE);
        return new ChartPanel(thePlot);
    }

    private XYSeriesCollection createLineXYSampleData(LinkedList<XYSeries> series, String Value) {
        XYSeriesCollection container = new XYSeriesCollection();
        series.add(new XYSeries("Best " + Value));
        series.add(new XYSeries("Worst " + Value));
        series.add(new XYSeries("Average " + Value));
        for (XYSeries xYSeries : series) {
            container.addSeries(xYSeries);
        }
        return container;
    }

    private void init() {
        //set tab titles
        this.tabPanel.setTitleAt(0, "Carga de Datos");
        this.tabPanel.setTitleAt(2, "Propiedades Simulacion");
        this.tabPanel.setTitleAt(1, "Ajuste de Operadores");
        this.useChart.setSelected(true);
        this.statics.setSelected(true);
        enableStadistics();
        //set  data for the validators
        Component[] comps = cargaDatos.getComponents();
        for (int i = 0; i < comps.length; i++) {
            Component component = comps[i];
            if (component instanceof JSpinner) {
                spinnersCargaDatos.add((JSpinner) component);
            }
        }
        this.velocidad.setValue(0);

        myChartPanelS = new HashMap<String, ChartPanel>();
        seriesFitness = new LinkedList<XYSeries>();
        seriesProfit = new LinkedList<XYSeries>();

        //set The combos
        this.scatterPlotCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[]{POPULATION_FITNESS, POPULATION_PROFIT}));
        this.linePlotterCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[]{AVERAGE_FITNESS, AVERAGE_PROFIT}));

        this.enablePlayButton(true);

        //setting selectors
        selectionCoverageMethods = new HashMap<SelectionManager.Selectors, Integer>();
        //setting cruzators
        cruzaCoverageMethods = new HashMap<CruzaManager.Cruzators, Integer>();
        //setting mutators
        mutationsCoverageMethods = new HashMap<MutatorManager.Mutators, Integer>();

        this.tabPanel.setAutoscrolls(true);

        this.mutatorPercentage.setValue(20);
        this.selectorPercentage.setValue(40);
        this.cruzaPercentage.setValue(40);

        this.elitista.setSelected(true);
        this.controlCopias.setSelected(true);
        this.ranking.setSelected(true);

        this.adder.setSelected(true);
        this.maximizer.setSelected(true);
        this.zeroMutation.setSelected(true);
        this.random.setSelected(true);

        this.binomial.setSelected(true);
        this.multipunto.setSelected(true);

        this.backBtn.setEnabled(false);
        this.nextBnt.setEnabled(false);
    }

    public void enablePlayButton(boolean value) {
        this.playBtn.setEnabled(value);
        inPauseStatus = !value;
        this.pauseBtn.setEnabled(!value);

    }

    private void enableStadistics() {
        boolean value = statics.isSelected();
        Component[] comps = stadistic.getComponents();
        for (int i = 0; i < comps.length; i++) {
            Component component = comps[i];
            if (component instanceof JPanel) {
                Component[] labels = ( (JPanel) component ).getComponents();
                for (int j = 0; j < labels.length; j++) {
                    Component currentLabel = labels[j];
                    currentLabel.setEnabled(value);
                }
            }
        }
    }

    public void updateProgress(final int progress) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                jProgressBar1.setValue(progress);
                if (progress == 100) {
                    enablePlayButton(true);
                }
            }
        });
    }

    public void resetCharts() {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                xySeriesCollectionLineXYFitnessPlot.removeAllSeries();
                xySeriesCollectionLineXYProfitPlot.removeAllSeries();

                xySeriesCollectionScatterFitnessPlot.removeAllSeries();
                xySeriesCollectionScatterProfitPlot.removeAllSeries();

                for (XYSeries xYSeries : seriesProfit) {
                    xYSeries.clear();
                    xySeriesCollectionLineXYProfitPlot.addSeries(xYSeries);
                }

                for (XYSeries xYSeries : seriesFitness) {
                    xYSeries.clear();
                    xySeriesCollectionLineXYFitnessPlot.addSeries(xYSeries);
                }

            }
        });
    }

    public void updateChart(final int theAge, final LinkedList<Individuo> data) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {

                    //sort the data
                    if (sortData.isSelected()) {
                        Collections.sort(data);
                    }

                    //get the serie for the scatter plot
                    XYSeries currentAgeSerieFitness = new XYSeries("Age " + theAge);
                    XYSeries currentAgeSerieProfit = new XYSeries("Age " + theAge);

                    Double averageFitness = 0.0;
                    Double averageProfit = 0.0;

                    Double bestProfit = 0.0;
                    Double bestFitness = Double.MAX_VALUE;

                    Double worstProfit = Double.MAX_VALUE;
                    Double worstFitnes = 0.0;

                    for (int i = 0; i < data.size(); i++) {
                        double myFitnessData = data.get(i).getFitnessValue();
                        double myProfitData = data.get(i).getProfit();

                        currentAgeSerieFitness.add(i, myFitnessData);
                        currentAgeSerieProfit.add(i, myProfitData);

                        averageFitness += myFitnessData;
                        averageProfit += myProfitData;

                        if (myFitnessData < bestFitness) {
                            bestFitness = myFitnessData;
                        }

                        if (myProfitData > bestProfit) {
                            bestProfit = myProfitData;
                        }

                        if (myFitnessData > worstFitnes) {
                            worstFitnes = myFitnessData;
                        }

                        if (myProfitData < worstProfit) {
                            worstProfit = myProfitData;
                        }
                    }

                    averageFitness = averageFitness / data.size();
                    averageProfit = averageProfit / data.size();

                    //update labels
                    if (statics.isSelected()) {
                        bestAptitud.setText(bestFitness.toString());
                        if (worstFitnes > worstAptitudNumber) {
                            worstAptitud.setText(worstFitnes.toString());
                            worstAptitudNumber = worstFitnes;
                        }

                        population.setText(String.valueOf(data.size()));
                        age.setText(theAge + "/" + iteracionesMaxima);

                        String promedio = averageFitness.toString();

                        int hasDot = promedio.indexOf(".");
                        if (( hasDot > 0 ) && ( promedio.length() > hasDot + 3 )) {
                            promedio = promedio.substring(0, hasDot + 3);
                        }

                        averageAptitud.setText(promedio);
                    }

                    if (popuView.isSelected()) {
                        populationView.setTableContents(data, theAge);
                    }
                    //ypdate chart
                    if (useChart.isSelected()) {

                        seriesFitness.get(0).add(theAge, bestFitness);
                        seriesFitness.get(1).add(theAge, worstFitnes);
                        seriesFitness.get(2).add(theAge, averageFitness);

                        seriesProfit.get(0).add(theAge, bestProfit);
                        seriesProfit.get(1).add(theAge, worstProfit);
                        seriesProfit.get(2).add(theAge, averageProfit);

                        updateScatterPlot(xySeriesCollectionScatterFitnessPlot, currentAgeSerieFitness);
                        updateScatterPlot(xySeriesCollectionScatterProfitPlot, currentAgeSerieProfit);
                    }


                }
                catch (Exception e) {
                    logguer.logError(e.getMessage());
                }

                if (inPauseStatus) {
                    backBtn.setEnabled(true);
                }
            }

            private void updateScatterPlot(XYSeriesCollection container, XYSeries series) {
                if (container.getSeriesCount() > 2) {
                    container.removeSeries(0);
                }
                container.addSeries(series);
            }
        });

    }

    public void saveImages() {
        Utils.saveToFile(myChartPanelS.get(POPULATION_PROFIT).getChart(), "poblacionGanancias");
        Utils.saveToFile(myChartPanelS.get(POPULATION_FITNESS).getChart(), "poblacionAptitud");
        Utils.saveToFile(myChartPanelS.get(AVERAGE_FITNESS).getChart(), "promedioAptitud");
        Utils.saveToFile(myChartPanelS.get(AVERAGE_PROFIT).getChart(), "promedioGanancias");
    }

    @Override
    public void dispose() {
        super.dispose();
        this.populationView.dispose();
    }
}
